﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Electure.DAL;

namespace Electure.Controls
{
    public partial class NewsList : System.Web.UI.UserControl
    {
        public List<DAL.News> Content { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            repNews.DataSource = Content;
            repNews.DataBind();
        }

        protected void repNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                var imgPreview = (Image)e.Item.FindControl("imagePreview");
                var instance = (News)e.Item.DataItem;
                if (instance.Image != null)
                    imgPreview.ImageUrl = ResolveUrl(instance.Image.GetFullPath());
            }
        }
    }
}